<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="layui-v2.6.8/layui/css/layui.css">
    <script src="jq/jquery1.9/jquery-1.9.0.js"></script>
    <script src="layui-v2.6.8/layui/layui.js"></script>

</head>

<body>
    <form class="layui-form" action="success.html">
        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-block">
                <input type="text" name="username" required lay-verify="username" placeholder="请输入用户名"
                    autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-block">
                <input type="text" name="password" required lay-verify="password" placeholder="请输入密码" autocomplete="off"
                    class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">确认密码</label>
            <div class="layui-input-block">
                <input type="text" name="repassword" required lay-verify="repassword" placeholder="请输入标题"
                    autocomplete="off" class="layui-input">
            </div>
        </div>


        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>

    <script>

        //使用form模块,加载form模块
        layui.use('form', function () {
            var form = layui.form;

            //自定义验证规则
            form.verify({
                username: function (value) {

                    // if(value.length < 5){
                    //     return '标题至少得5个字符啊';
                    // }

                    var reg = /^[a-z]{6,10}$/;
                    if (!reg.test(value)) {
                        return '用户名是字母组成，并且是6-10位';
                    }



                },
                // username:[/^[a-z]{6,10}$/,"用户名是字母组成，并且是6-10位"],
                password: [/^[0-9]{3,6}$/, '密码必须3到6位'],
                repassword: function (value) {
                    if (value != $("input[name='password']").val()) {
                        return "两次密码输入不一致";
                    }


                }

            });
            // 监听提交
            form.on('submit(formDemo)', function (data) {
                localStorage.setItem("username",$("input[name='username']").val());
                return true;//允许提交
                // return false;//阻止表单提交
            });
        });
    </script>
</body>

</html>